package com.simpleaccount.Add;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.simpleaccount.Common.Utils;
import com.simpleaccount.Db.DbUtils;
import com.simpleaccount.Entity.Category;
import com.simpleaccount.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 超 on 2017/7/13.
 */

public class IncomeFragment extends Fragment {

    //    @Bind(R.id.tv_income)
//    TextView tvIncome;

    @Bind(R.id.redpackage)
    ImageView redpackage;
    @Bind(R.id.bonus)
    ImageView bonus;
    @Bind(R.id.earnings)
    ImageView earnings;
    @Bind(R.id.part_time_job)
    ImageView partTimeJob;
    @Bind(R.id.salary)
    ImageView salary;
//    @Bind(R.id.other_income)
//    ImageView otherIncome;
    @Bind(R.id.general_income)
    ImageView generalIncome;

    public String category="普通";

    public interface Callback
    {
        public void getCategory(String category);
    }

    public List<String> getData() {
        List<String> list = new ArrayList<>();
        for (Category e : DbUtils.getCategory(1)) {
            list.add(e.getName());
        }
        return list;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_income, container, false);
        ButterKnife.bind(this, view);

//        MySpinnerAdapter adapter = new MySpinnerAdapter(getActivity(), getData());
//        spinner_income.setAdapter(adapter);

        Utils.setImage(generalIncome, "普通");
        Utils.setImage(redpackage, "红包");
        Utils.setImage(bonus, "奖金");
        Utils.setImage(earnings, "生活费");
        Utils.setImage(partTimeJob, "兼职");
//        Utils.setImage(otherIncome, "其他");
        Utils.setImage(salary, "工资");
        onclicked("普通");

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        //ButterKnife.unbind(this);
        ButterKnife.unbind(this);
    }
    public  void onclicked(String str){
        getActivity().findViewById(R.id.ll_numberbackgroundcolor).setBackgroundColor(DbUtils.getCategory(str).getColor());
        ((TextView)getActivity().findViewById(R.id.tv_number)).setTextColor(Color.parseColor("#000000"));
        ((TextView)getActivity().findViewById(R.id.tv_money)).setTextColor(Color.parseColor("#000000"));
        ((TextView)getActivity().findViewById(R.id.tv_number)).setHintTextColor(Color.parseColor("#000000"));
        category=str;
    }

    @OnClick({R.id.general_income, R.id.redpackage, R.id.bonus, R.id.earnings, R.id.part_time_job, R.id.salary})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.general_income:
                onclicked("普通");

                break;
            case R.id.redpackage:
                onclicked("红包");
                break;
            case R.id.bonus:
                onclicked("奖金");
                break;
            case R.id.earnings:
                onclicked("生活费");
                break;
            case R.id.part_time_job:
                onclicked("兼职");
                break;
            case R.id.salary:
                onclicked("工资");
                break;
        }
    }
    public void setCategory(Callback callback){
        callback.getCategory(category);
    }
}
